package com.kgc.controller;

import com.kgc.basic.pojo.Good;
import com.kgc.basic.util.ResponseMsg;
import com.kgc.feign.GoodFeign;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/good")
public class GoodController {
    @Autowired
    private GoodFeign goodFeign;

    private Logger logger = LoggerFactory.getLogger(getClass());

    @RequestMapping("getGoodPage")
    @ResponseBody
    ResponseMsg getGoodPage(String pageNow, String pageSize, String combine, String kid) {
        logger.info("GoodController getGoodPage pageNow:" + pageNow + ",pageSize:" + pageSize + ",combine:" + combine + ",kid:" + kid);
        Map<String, Object> map = new HashMap<>();
        map.put("pageNow", pageNow);
        map.put("pageSize", pageSize);
        map.put("combine", "%" + combine + "%");
        map.put("kid", kid);
        ResponseMsg responseMsg = goodFeign.getGoodPage(map);
        logger.info("GoodController getGoodPage responseMsg:" + responseMsg);
        return responseMsg;
    }
    @RequestMapping("getAll")
    @ResponseBody
    ResponseMsg getAll() {
        logger.info("BOMController getAll");
        HashMap<String, Object> map = new HashMap<>();
        ResponseMsg responseMsg = goodFeign.getAllGood(map);
        logger.debug("BOMController getAll responseMsg:" + responseMsg + ",map:" + map);
        return responseMsg;
    }

    @RequestMapping("addGood")
    @ResponseBody
    ResponseMsg addGood(@RequestBody Good good) {
        logger.info("GoodController addGood good:" + good);
        ResponseMsg responseMsg = goodFeign.addGood(good);
        logger.info("GoodController addGood responseMsg:" + responseMsg);
        return responseMsg;
    }

    @RequestMapping("updateGood")
    @ResponseBody
    ResponseMsg updateGood(@RequestBody Good good) {
        logger.info("GoodController updateGood good:" + good);
        ResponseMsg responseMsg = goodFeign.updateGood(good);
        logger.info("GoodController updateGood responseMsg:" + responseMsg);
        return responseMsg;
    }

    @RequestMapping("delGood")
    @ResponseBody
    ResponseMsg delGood(String id) {
        logger.info("GoodController delGood id:" + id);
        ResponseMsg responseMsg = goodFeign.delGood(id);
        logger.info("GoodController delGood responseMsg:" + responseMsg);
        return responseMsg;
    }

    @RequestMapping("getGoodById")
    @ResponseBody
    public ResponseMsg getGoodById(String id) {
        logger.info("GoodController getGoodById id:" + id);
        ResponseMsg responseMsg = goodFeign.getGoodById(id);
        logger.info("GoodController getGoodById responseMsg:" + responseMsg);
        return responseMsg;
    }

    @RequestMapping("getGoodList")
    @ResponseBody
    public ResponseMsg getGoodById(@RequestBody List<String> idList) {
        logger.info("GoodController getGoodList idList:" + idList);
        ResponseMsg responseMsg = goodFeign.getGoodList(idList);
        logger.info("GoodController getGoodList responseMsg:" + responseMsg);
        return responseMsg;
    }
}
